package cn.itcast.oa.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.oa.base.DaoSupportImpl;
import cn.itcast.oa.domain.Forum;
import cn.itcast.oa.domain.Reply;
import cn.itcast.oa.domain.Topic;
import cn.itcast.oa.service.ReplyService;

@Service
@Transactional
@SuppressWarnings("all")
public class ReplyServiceImpl extends DaoSupportImpl<Reply> implements ReplyService {

	public void save(Reply reply) {
		getSession().save(reply);

		// 维护相关的信息
		Topic topic = reply.getTopic();
		Forum forum = topic.getForum();

		forum.setArticleCount(forum.getArticleCount() + 1); // 文章数加1

		topic.setReplyCount(topic.getReplyCount() + 1); // 回复数加1
		topic.setLastReply(reply); // 最后回复
		topic.setLastUpdateTime(reply.getPostTime()); // 最后更新时间更新为最后回复时间

		getSession().update(forum);
		getSession().update(topic);

	}
}
